package cn.cxion.chat.app.activity;

import android.content.Context;
import android.content.Intent;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import cn.cxion.chat.R;
import cn.cxion.chat.app.Fragment.CheckFragment;
import cn.cxion.chat.app.Fragment.ClaimFragment;
import cn.cxion.chat.app.Fragment.SendFragment;
import cn.cxion.chat.app.bean.CheckContractBean;
import cn.cxion.chat.app.main.HomeFragmentPagerAdapter;
import cn.cxion.chat.kit.WfcBaseActivity;

/**
 * 待处理通用页面
 *
 * @author qiancheng
 **/
public class CheckContractActivity extends WfcBaseActivity implements ViewPager.OnPageChangeListener {


    int classType;
    @Bind(R.id.contentViewPager)
    ViewPager contentViewPager;
    @Bind(R.id.navigationView)
    BottomNavigationView navigationView;
    CheckContractBean checkContractBean;
    ClaimFragment claimFragment;
    CheckFragment checkFragment;
    SendFragment sendFragment;
    public static void show(Context context, int classType) {
        Intent intent = new Intent();
        intent.setClass(context, CheckContractActivity.class);
        intent.putExtra("classType", classType);
        context.startActivity(intent);
    }
public static void show(Context context, int classType, CheckContractBean checkContractBean) {
        Intent intent = new Intent();
        intent.setClass(context, CheckContractActivity.class);
        intent.putExtra("classType", classType);
        intent.putExtra("checkContractBean",checkContractBean);
        context.startActivity(intent);
    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_pending;
    }

    @Override
    protected void afterViews() {
        super.afterViews();
        classType = getIntent().getIntExtra("classType", 0);
        checkContractBean= (CheckContractBean) getIntent().getSerializableExtra("checkContractBean");
        initView();
    }

    public void initView() {
        setTitle("合同审改");
        List<Fragment> fragments =new ArrayList<>();
        claimFragment=new ClaimFragment();
        claimFragment.setCheckContractBean(checkContractBean);
        checkFragment =new CheckFragment();
        checkFragment.setCheckContractBean(checkContractBean);
        sendFragment=new SendFragment();
        fragments.add(claimFragment);
        fragments.add(checkFragment);
        fragments.add(sendFragment);
        //设置ViewPager的最大缓存页面
        contentViewPager.setOffscreenPageLimit(2);
        contentViewPager.setAdapter(new HomeFragmentPagerAdapter(getSupportFragmentManager(),fragments));
        contentViewPager.setOnPageChangeListener(this);
        navigationView.setOnNavigationItemSelectedListener(item -> {
            switch (item.getItemId()) {
                case R.id.menu_claim:
                    contentViewPager.setCurrentItem(0);
                    break;
                case R.id.menu_check:
                    contentViewPager.setCurrentItem(1);
                    break;
                case R.id.menu_send:
                    contentViewPager.setCurrentItem(2);
                    break;
                default:
                    break;
            }
            return true;
        });
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                navigationView.setSelectedItemId(R.id.menu_claim);
                break;
            case 1:
                navigationView.setSelectedItemId(R.id.menu_check);
                break;
            case 2:
                navigationView.setSelectedItemId(R.id.menu_send);
                break;
            default:
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
